package com.itheima.d7_tcp4;


import com.itheima.d6_tcp3.TheardServe;

import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

/*
   目标：完成TCP通信快速入门-服务端开发：实现1发1收。
 */
public class Server {
    public static ArrayList<Socket> list = new ArrayList<>();
    public static void main(String[] args) throws Exception {
        // 1、创建ServerSocket的对象，同时为服务端注册端口。
        ServerSocket ss = new ServerSocket(1001);
        InetAddress localHost = InetAddress.getLocalHost();
        String hostAddress = localHost.getHostAddress();
        // 2、使用serverSocket对象，调用一个accept方法，等待客户端的连接请求

        while (true) {
            Socket accept = ss.accept();
            list.add(accept);
            TheardServe theardServe = new TheardServe(accept);
            Thread thread = new Thread(theardServe);
            System.out.println(hostAddress);
            thread.start();
        }
        // 3、从socket通信管道中得到一个字节输入流。

    }

}













